﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using WebComponents.Data;
using System.Data;

namespace WebComponents.UI.Controls
{
    public static class ConvertDropDownList
    {
        public static void LoadDropDownList(DropDownList ddl, string query, string textField, string valueField, string selectedField, string selectedValue)
        {
            List<GetData.ISqlParameter> param = new List<GetData.ISqlParameter>();
            DataTable dt = new DataTable();
            dt = GetData.DataTable(query, null);
            ddl.Items.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                ddl.Items.Add(new ListItem(dr[textField].ToString(), dr[valueField].ToString()));
                if (selectedField != null)
                {
                    if (dr[selectedField].ToString() == selectedValue)
                        ddl.SelectedValue = dr[valueField].ToString();
                }

            }
        }
    }
}
